package cn.dnui_lf_705.dnui_16110100705.controller;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.List;

import cn.dnui_lf_705.dnui_16110100705.Adapter.BuyAdapter;
import cn.dnui_lf_705.dnui_16110100705.R;
import cn.dnui_lf_705.dnui_16110100705.bean.CommentBean;
import cn.dnui_lf_705.dnui_16110100705.listener.OnRetrofitListener;
import cn.dnui_lf_705.dnui_16110100705.model.UserModel;


public class BuyActivity extends BaseActivity implements OnRetrofitListener<List<CommentBean>> {
    private RecyclerView recyclerView;
    private BuyAdapter buyAdapter;
    SharedPreferences sharedPreferences;
    private String user_id;
    @Override
    void initViews() {
        recyclerView = findViewById(R.id.dingdan_re);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
    }

    @Override
    void initEvents() {

    }

    @Override
    void initData() {
        sharedPreferences = getSharedPreferences("yht",Context.MODE_PRIVATE);
        user_id = sharedPreferences.getString("user_id","");
        UserModel userModel = new UserModel();
        userModel.getAllOrdersByUser(user_id,this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_buy);
        initViews();
        initData();
        initEvents();
        if (setEnableSliding()) {
            ArActSlidLayout rootView = new ArActSlidLayout(this);
            rootView.bindActivity(this);//绑定需要窗口的布局：
        }
    }
    protected boolean setEnableSliding() {//默认返回是需要的，只需继承的时候重写次代码 true : 需要；false :不需要；
        return true;
    }

    @Override
    public void onsuccess(List<CommentBean> commentBeans, int flag) {
        buyAdapter = new BuyAdapter(BuyActivity.this,commentBeans);
        recyclerView.setAdapter(buyAdapter);
    }

    @Override
    public void onFailure(String string) {
        showToast("获取订单信息失败");
    }
}
